package com.itheima.dao;

import com.itheima.pojo.Order;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

public interface UserMapper {


    @Select("SELECT * FROM tb_user WHERE id=#{id}")
    @Results({
        @Result(column = "id",property = "id",id = true),
        @Result(column = "user_name",property = "userName")
    })
    User findUbyId(int id);


    @Select("SELECT\n" +
            "\tu.*,\n" +
            "\to.id oid,\n" +
            "\to.order_number,\n" +
            "\ti.id iid,\n" +
            "\ti.item_name,\n" +
            "\ti.item_price,\n" +
            "\ti.item_detail \n" +
            "FROM\n" +
            "\ttb_user u,\n" +
            "\ttb_order o,\n" +
            "\ttb_orderdetail z,\n" +
            "\ttb_item i \n" +
            "WHERE\n" +
            "\to.id = z.order_id \n" +
            "\tAND z.item_id = i.id \n" +
            "\tAND u.id = o.user_id \n" +
            "\tAND u.id = 2;")
    @Results({
            @Result(column = "id",property = "id" ,id = true),
            @Result(column = "user_name",property = "userName" ),
            @Result(column = "oid" ,property ="orders" ,many=@Many( //一对多指向查询 用户id 对应的订单id
                    select = "com.itheima.dao.OrderMapper.findOrderByUid"
            ))

    })
    User find0002(int id);
}
